﻿
<div class="btn-group">
    <button class="btn @GetClass("苹果")" @onclick="@(e=>OnValueChanged("苹果"))">苹果</button>
    <button class="btn @GetClass("香蕉")" @onclick="@(e=>OnValueChanged("香蕉"))">香蕉</button>
    <button class="btn @GetClass("葡萄")" @onclick="@(e=>OnValueChanged("葡萄"))">葡萄</button>
</div>

@code{

    string? GetClass(string value) => value == Value ? "btn-primary" : "btn-outline-primary";

    [Parameter] public string? Value { get; set; }
    [Parameter]public EventCallback<string?> ValueChanged{get;set;}

    Task OnValueChanged(string? value)
    {
        Value = value;
        ValueChanged.InvokeAsync(value);
        return Task.CompletedTask;
    }
}